import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
  // 首页我们需要默认空路径重定向到 home 下，避免空页面
  {
    path: "/",
    // name: "home",
    redirect: "home",
    meta: {
      index: 1,
    },
  },
  {
    path: "/home",
    name: "home",
    component: Home,
  },
  {
    path: "/about",
    name: "about",
    component: () => import("../views/AboutView.vue"),
    meta: {
      index: 2, // 添加 meta 属性，约定 2 为第二级
    },
  },
  {
    path: "/category",
    name: "category",
    component: () => import("../views/Category.vue"),
    meta: {
      index: 1,
    },
  },
  {
    path: "/cart",
    name: "cart",
    component: () => import("../views/Cart.vue"),
    meta: {
      index: 1,
    },
  },
  {
    path: "/user",
    name: "user",
    component: () => import("../views/User.vue"),
    meta: {
      index: 1,
    },
  },
  {
    path: "/detail",
    name: "detail",
    component: () => import("../views/Detail.vue"),
    meta: {
      index: 2,
    },
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/Login.vue"),
    meta: {
      index: 1,
    },
  },
];

const router = new VueRouter({
  routes,
});

export default router;
